import { RootState } from "../index";
import { Module } from "vuex"

export interface UserState {
  isLogin: boolean;
  nickname: string;
  avator: string;
  username: string;
  token: string;
}

const store: Module<UserState, RootState> =  {
  namespaced: true,
  state: (): UserState => {
		return {
			isLogin: false,
			nickname: "",
			avator: "",
			username: "",
			token: localStorage.getItem("token") || "",
		}
	},
  mutations: {
    setUser(state, payload: UserState) {
      state.avator = payload.avator
      state.nickname = payload.nickname
      state.isLogin = payload.isLogin
      state.username = payload.username
      state.token = payload.token
    },
  },
};

export default store
